import { observable, action } from 'mobx';
import { SelectPage } from 'weaver-mobile-page';
import { Tools } from 'weaver-mobile'
import * as API from '../../api/oneWeek';
const getLabel = Tools.getLabel;

export default class OneWeekStore {
  @observable loadding = false;
  @observable init = false;
  @observable selectGroup = [];
  @observable selectedType = [];
  @observable selectPage = new SelectPage.Store({ route: '/calendar/myCalendar/report/oneWeekWorkplan' });
  @observable oneWeekDatas = [];
  @observable showNight = false;
  @observable showNoon = false;

  @observable selectedDate = '';
  @observable groupId = '';
  @observable weekStartDate = '';
  @observable weekEndDate = '';
  @observable isStyleX = false;
  @observable status = {
    current: 'oneweek'
  };

  @action 
  setState = (params = {}) => {
    Object.keys(params).forEach(key => {
      this[key] = params[key]
    })
  }

  // 选择查看日程类型
  getWorkPlanWeekGroupSelect = (callback) => {
    this.selectedType = [];
    API.getWorkPlanWeekGroupSelect().then(res => {
      if(res.api_status && res) {
        if (res.selectGroup && res.selectGroup[0]) {
          this.selectGroup = res.selectGroup;
          this.groupId = this.status.current == 'oneweek' ? res.selectGroup[0].key : this.groupId;
        } else {
          this.selectGroup = [
            { showname: getLabel('509729','暂无可查看的数据') , key: '-1' }
          ];
          this.groupId = this.status.current == 'oneweek' ? '-1' : this.groupId;
        }
        this.selectedType.push(this.groupId);
        typeof callback === 'function' && callback({selectDate: this.selectedDate, groupId: this.groupId});
      }
    });
  }

  // 一周日程安排日程数据
  getWorkPlanWeekData = (params) => {
    this.loadding = true;
    API.getWorkPlanWeekData(params).then(res => {
      this.loadding = false;
      this.init = true;
      this.oneWeekDatas = [];
      if(res.api_status && res) {
        this.showNight = res.showNight;
        this.showNoon = res.showNoon;
        this.weekStartDate = res.beginDate;
        this.weekEndDate = res.endDate;
        this.oneWeekDatas = res.datas;
      }
    });
  }

}

